package com.shd.edanpei.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.shd.edanpei.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by mc on 2018/10/25.
 * yang-wen-wen
 */

public class LoginView extends LinearLayout {

    private final int SMALL = 16;
    private final int BIG = 18;

    @BindView(R.id.radio_group)
    RadioGroup radioGroup;
    @BindView(R.id.radio_button_login)
    RadioButton rbtLogin;
    @BindView(R.id.radio_button_signup)
    RadioButton rbtSignUp;
    @BindView(R.id.child_login_layout)
    View layoutLogin;
    @BindView(R.id.child_signup_layout)
    View layoutSignup;

    @BindView(R.id.et_login_account)
    EditText etAccount;
    @BindView(R.id.et_login_password)
    EditText etPassword;


    private Context context;
    private int currentLayoutID;//当前布局id

    public LoginView(Context context) {
        super(context);
        initView(context);
    }

    public LoginView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public LoginView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }


    private void initView(Context context) {
        this.context = context;
        inflate(context, R.layout.view_login, this);
        ButterKnife.bind(this);

        layoutSignup = findViewById(R.id.child_signup_layout);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                changeTab(checkedId);
            }
        });

        changeTab(R.id.radio_button_login);
    }


    //切换布局
    private void changeTab(int id) {
        if (id == currentLayoutID) {
            return;
        }
        switch (id) {
            case R.id.radio_button_login:
                //切换登录页
                rbtLogin.setTextSize(BIG);
                rbtSignUp.setTextSize(SMALL);
                layoutLogin.setVisibility(View.VISIBLE);
                layoutSignup.setVisibility(View.GONE);
                break;
            case R.id.radio_button_signup:
                //切换注册页
                rbtLogin.setTextSize(SMALL);
                rbtSignUp.setTextSize(BIG);
                layoutSignup.setVisibility(View.VISIBLE);
                layoutLogin.setVisibility(View.GONE);
                break;
            default:
                break;
        }
        currentLayoutID = id;
    }

}
